package net.lb.socketclient.filter;

import net.lb.baseutil.collection.ByteCache;
import net.lb.baseutil.encrypt.DesUtil;

public class DesFilter implements EndecrptFilter
{
    private byte[]  key;
    private DesUtil desUtil = new DesUtil();
    
    @Override
    public void outFilter(ByteCache cache)
    {
        byte[] result = desUtil.encrypt(cache.toArray());
        cache.clear().putArray(result);
    }
    
    @Override
    public void inFilter(ByteCache cache)
    {
        byte[] result = desUtil.decrypt(cache.toArray());
        cache.clear().putArray(result);
    }
    
    public byte[] getKey()
    {
        return key;
    }
    
    public void setKey(byte[] key)
    {
        this.key = key;
        desUtil = new DesUtil();
        desUtil.setKey(key);
    }
    
}
